package com.numbfish.ch02_ex01_aop.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Aspect
public class AnnotationAspect {
    @Pointcut("@within(com.numbfish.ch02_ex01_aop.aop.MyAnnotation)")
    public void pointcut(){}
    //@Before("pointcut()")
    //@Before("execution(* com.numbfish.ch02_ex01_aop.service.MyCalculator.div(..))")
    @Before("@annotation(myAnnotation)") // @annotation(myAnnotation) 切到方法上有myAnnotation注解的方法
    public void start(MyAnnotation myAnnotation){
        System.out.println("@Before 执行了start");
        System.out.println(myAnnotation.annotationType());
    }
    @After("pointcut()")
    public void end(){
        System.out.println("@After");
    }

    @AfterReturning("pointcut()")
    public void returning(){
        System.out.println("@AfterReturning");
    }
    @AfterThrowing("pointcut()")
    public void returnExcepting(){
        System.out.println("@AfterThrowing");
    }

    @Around("pointcut()")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("@Around begin");
        joinPoint.proceed();
        System.out.println("@Around end");
    }
}
